/*
 * MovingBomb.cpp
 *
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses 
 */

#include "MovingBomb.h"
#include "ModelConstants.h"
#include "MovStrategyFactory.h"
#include "../common/Properties.h"
#include <iostream>

MovingBomb::MovingBomb(int x, int y, int direction)
    : MovingObject(x, y) {
    this->direction = direction;
    mov_strategy = MovStrategyFactory::createMovementStrategy(BOMB, this);
    Properties properties = Properties();
    speed = properties.getPropertyAsInt("bomb_speed");
}

void MovingBomb::receiveDamage(int damage, MapObject* from) {
    //No-op
    (void)0;
}

bool MovingBomb::isDestroyed() {
    return triggered;
}

bool MovingBomb::collideWith(MapObject* object) {
    if (! triggered) {
        triggered = true;
        if (object->getAlignment() == AL_NEUTRAL) {
            x = last_x;
            y = last_y;
        }
        explode();
    }
    return object->getCollidedBy(this);
}

bool MovingBomb::getCollidedBy(MapObject* object) {
    if (! triggered) {
        triggered = true;
        explode();
    }
    return true;
}

MovingBomb* MovingBomb::clone() {
    MovingBomb* clone = new MovingBomb(*this);
    clone->mov_strategy = MovStrategyFactory::createMovementStrategy(BOMB, clone);
    return clone;
}

ModelObject MovingBomb::getRepresentation() {
    return BOMB;
}
